#include "Post.h"

#include <pcrecpp.h>

using namespace pcrecpp;

Post::Post()
{
}

Post::~Post()
{
}

ostream & operator<<(ostream & out, Post & post)
{
    out << "[Post: title=" << post.title << ", author=" << post.
	author << ", description=" << post.
	description << ", content=" << post.getContentStripped().substr(0,
									100)
	<< "]";

    return out;
}

static void rreplace(string regex, string replacement, string& str)
{
    RE r(regex);
    r.GlobalReplace(replacement, &str);
}

string Post::getContentStripped()
{
    string stripped = this->content;
    rreplace("<[a-zA-Z\\/][^>]*>", "", stripped);
    rreplace("&lt;", "<", stripped);
    rreplace("&gt;", ">", stripped);
    rreplace("&amp;", "&", stripped);
    rreplace("&[^;]{1,10};", "", stripped);
    rreplace("[“”]+", "\"", stripped);
    rreplace("[’]+", "'", stripped);

    return stripped;
}
